# Contributor: Tom Parker-Shemilt <palfrey@tevp.net>
# Maintainer: Sodface <sod@sodface.com>
pkgname=netpbm
pkgver=11.5.1
pkgrel=0
pkgdesc="Toolkit for manipulation of graphic images"
url="https://netpbm.sourceforge.net/"
arch="all"
license="IJG AND BSD-3-Clause AND GPL-2.0-only"
checkdepends="diffutils musl-locales"
makedepends="
	bash
	flex
	ghostscript
	libjpeg-turbo-dev
	libpng-dev
	libx11-dev
	libxml2-dev
	perl
	sed
	tiff-dev
	zlib-dev
	"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-extras::noarch"
source="https://github.com/ceamac/netpbm-make-dist/releases/download/v$pkgver/netpbm-$pkgver.tar.xz
	config.mk
	manweb.conf
	01-makefile.patch
	02-installnetpbm.patch
	"

# ps-roundtrip, ps-flate-roundtrip, winicon-roundtrip2, stdin-pnm2
case "$CARCH" in
arm*|aarch64) options="!check" ;;
esac

build() {
	cat config.mk.in "$srcdir"/config.mk > config.mk

	make
	make package pkgdir="$PWD/pkgdir"
}

check() {
	# disable failing tests
	sed -i -e '/^pbmtext-iso88591.test/d' \
		-e '/^ppmpat-random.test/d' \
		-e '/^ppmtomitsu.test/d' \
		-e '/^stdin-pam3.test/d' \
		-e '/^stdin-pnm2.test/d' \
		-e '/^ps-roundtrip.test/d' \
		-e '/^ps-flate-roundtrip.test/d' \
		-e '/^pnmindex.test/d' \
		"$builddir"/test/Test-Order

	make check pkgdir="$PWD/pkgdir"
}

package() {
	mkdir -p "$pkgdir"/usr/bin/ \
		"$pkgdir"/usr/lib/pkgconfig

	BUILDDIR="$builddir" PKGDIR="$pkgdir" ./installnetpbm

	# stray symlink named '*' because target dir does not exist
	rm "$pkgdir"/usr/include/\*

	sed -i -e "s|$pkgdir||g" "$pkgdir"/usr/lib/pkgconfig/netpbm.pc

	install -Dm644 -t "$pkgdir"/etc "$srcdir"/manweb.conf

	install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname/html \
		"$builddir"/userguide/*.html

	install -Dm644 "$builddir"/doc/copyright_summary \
		"$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

doc() {
	default_doc
	depends="perl lynx"

	amove etc/manweb.conf
	amove usr/bin/manweb
}

extras() {
	pkgdesc="$pkgdesc (perl scripts)"
	depends="perl"

	amove usr/bin/pamfixtrunc
	amove usr/bin/pbmtox10bm
	amove usr/bin/pgmcrater
	amove usr/bin/pnmflip
	amove usr/bin/pnmquant
	amove usr/bin/pnmquantall
	amove usr/bin/ppmfade
	amove usr/bin/ppmquant
	amove usr/bin/ppmquantall
	amove usr/bin/ppmrainbow
	amove usr/bin/ppmshadow
}

sha512sums="
05fa20fdabc175c99c89e779ffa719b0447ce97b4a6851f17afdf247dd3e67787ce251e28b5529bb793d46164b0c3908a368a77e0a5245c49109767f7870676d  netpbm-11.5.1.tar.xz
7dc16e0ad3229fac35c3ddecdbfb43ebfb1a2b778e53ca34d5f45f738e15fd131298bc8faa6b9a428380ffa4f1c9b2101934b79fe37bb7e6c046910fcf8ac45c  config.mk
bfd56c3c071528e5a5eac9455bdb0f4fbe524159d28291f65c6d5cda6cb31ac96efffb3f671f308007d3af8e69480423a8eb92bc54d9545ced45b9980c108571  manweb.conf
098f4270b20b585559fcd6ba088c5294ebfac02e912ed1f86577550c2b45bc7c61a22e9be1177116bdb7b21e51f0758b5612cd6eef2b0f03e8de06a69e241529  01-makefile.patch
792299b4f5a676f409367f442fe3a00d2688da3f40c1cb2f3953ddc56c7f6d595b1f81f255b23e3210ac0c20e9025e365e8543ba5a0e5c35e26bc14cc1ab691d  02-installnetpbm.patch
"
